import { http } from './request'

// 用户相关API
export const userApi = {
  // 获取加密公钥
  getServerPublicKey() {
    return http.get('/auth/getServerPublicKey', null)
  },
  // 获取验证码
  getCode(data) {
    return http.get('/auth/sms/code', data)
  },
  // 用户登录
  login(data) {
    return http.post('/auth/login', data)
  },
  
  // 用户注册
  register(data) {
    return http.post('/user/register', data)
  },
  
  // 获取用户信息
  getUserInfo() {
    return http.get('/user/info')
  },
  
  // 更新用户信息
  updateUserInfo(data) {
    return http.put('/user/info', data)
  },
  
  // 用户登出
  logout() {
    return http.post('/user/logout')
  }
}

// 文件上传API
export const uploadApi = {
  // 上传文件
  uploadFile(file, onProgress) {
    return http.upload('/upload/file', file, onProgress)
  },
  
  // 上传图片
  uploadImage(file, onProgress) {
    return http.upload('/upload/image', file, onProgress)
  }
}

// 通用API
export const commonApi = {
  // 获取配置信息
  getConfig() {
    return http.get('/config')
  },
  
  // 获取字典数据
  getDict(type) {
    return http.get('/dict', { type })
  }
}

// 导出所有API
export default {
  user: userApi,
  upload: uploadApi,
  common: commonApi
}